{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "polished-click",
   "metadata": {
    "papermill": {
     "duration": 0.0052,
     "end_time": "2021-03-12T08:33:43.246663",
     "exception": false,
     "start_time": "2021-03-12T08:33:43.241463",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Applies function on pandas data frame\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "gentle-lightning",
   "metadata": {
    "papermill": {
     "duration": 28.520857,
     "end_time": "2021-03-12T08:34:11.772333",
     "exception": false,
     "start_time": "2021-03-12T08:33:43.251476",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "!pip3 install pandas==1.2.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "unavailable-antenna",
   "metadata": {
    "papermill": {
     "duration": 0.267363,
     "end_time": "2021-03-12T08:34:12.062325",
     "exception": false,
     "start_time": "2021-03-12T08:34:11.794962",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "generous-margin",
   "metadata": {
    "papermill": {
     "duration": 0.020275,
     "end_time": "2021-03-12T08:34:12.098601",
     "exception": false,
     "start_time": "2021-03-12T08:34:12.078326",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# @param column where function needs to be applied\n",
    "# @param function to be applied on data element\n",
    "# @param file_name csv file name\n",
    "# @returns updated csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "gross-click",
   "metadata": {
    "papermill": {
     "duration": 0.021922,
     "end_time": "2021-03-12T08:34:12.137016",
     "exception": false,
     "start_time": "2021-03-12T08:34:12.115094",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "column = os.environ.get('column')\n",
    "function = os.environ.get('function')\n",
    "file_name = os.environ.get('file_name', 'metadata.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "sought-navigation",
   "metadata": {
    "papermill": {
     "duration": 0.086226,
     "end_time": "2021-03-12T08:34:12.240530",
     "exception": true,
     "start_time": "2021-03-12T08:34:12.154304",
     "status": "failed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "metadata = pd.read_csv(file_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "apart-electricity",
   "metadata": {
    "papermill": {
     "duration": null,
     "end_time": null,
     "exception": null,
     "start_time": null,
     "status": "pending"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "lf = 'dummy'  # to make the compiler happy\n",
    "exec('lf = lambda x: x.' + function)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "mexican-harvey",
   "metadata": {
    "papermill": {
     "duration": null,
     "end_time": null,
     "exception": null,
     "start_time": null,
     "status": "pending"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "metadata[column] = metadata[column].apply(lf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "amended-blocking",
   "metadata": {
    "papermill": {
     "duration": null,
     "end_time": null,
     "exception": null,
     "start_time": null,
     "status": "pending"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "metadata.to_csv(file_name, index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 31.039908,
   "end_time": "2021-03-12T08:34:13.465890",
   "environment_variables": {},
   "exception": true,
   "input_path": "/home/jovyan/work/examples/pipelines/claimed_covid_ct_trusted_ai/component-library/transform/transform-apply.ipynb",
   "output_path": "/home/jovyan/work/examples/pipelines/claimed_covid_ct_trusted_ai/component-library/transform/transform-apply.ipynb",
   "parameters": {},
   "start_time": "2021-03-12T08:33:42.425982",
   "version": "2.3.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
